﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ViVa.ActiveDirectory;
using System.Data;
using System.Web.Services;

namespace ViVa_Portal.Controllers
{
    public class LogController : Controller
    {
        //
        // GET: /Log/

        public ActionResult Index()
        {
            List<Logging> logList = DataFiller<Logging>.FromDataTableToList(Logging.getLogTypes());
            return View(logList);
        }

        public ActionResult showLog(Logging log)
        {
            var list = DataFiller<Logging>.FromDataTableToList(Logging.getLog(log.Type_ID));
            ViewData["paginaNaam"] = log.Type_log;
            ViewBag.LogList = DataFiller<Logging>.FromDataTableToList(Logging.getLog(log.Type_ID, true));
            return View(list);
        }

        public ActionResult makeLog(string message, int Type_ID, string logUser = "geen")
        {
            if (logUser == "geen")
            {
                logUser = PermissionService.userName();
            }
            if (message != null && message != "" && message != "Geef hier uw invoer..." && logUser != "Wie heeft dit gezegt?")
            {
                Logging.Log(logUser, Type_ID, message);
            }
            var log = new Logging{ Type_ID = Type_ID};
            return RedirectToAction("showLog", log); 
        }

        public ActionResult verwijderLog(Logging log)
        {
            Logging.deleteLog(log);
            return RedirectToAction("showLog", log);
        }
    }
}
